package com.auto.api.core.entity;

import com.auto.api.core.util.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import java.lang.reflect.Field;
import lombok.Data;
import lombok.ToString;

/**
 * @program:
 * @description:
 * @author: liangshf
 * @create: 2022-05-16
 */
@Data
@ToString
public class ProcessProp <Q extends ParseTypeContext>{

    private String propType;
    private Q context;
    private PropertyContext propertyContext;
    private ApiModelProperty fieldApiModel;


    private StringBuilder propTypeValue;

    private String attrKey;

    public ProcessProp() {}


    public ProcessProp(String propType, Q context, PropertyContext propertyContext) {
        this.propType = propType;
        this.context = context;
        this.propertyContext = propertyContext;
    }

    public ProcessProp(String propType, Q context, PropertyContext propertyContext, String attrKey, StringBuilder propTypeValue) {
        this.propType = propType;
        this.context = context;
        this.propertyContext = propertyContext;
        this.attrKey = attrKey;
        this.propTypeValue = propTypeValue;

        fieldApiModel = getFieldApiModel(context, propertyContext.getProp().getName());
    }

    private ApiModelProperty getFieldApiModel(Q context, String propertyName) {
        Field field = BeanUtil.getField(context.getClazz(), propertyName);
        return field.getAnnotation(ApiModelProperty.class);
    }

}